Fun example for learning dplyr and tidyr not to be used for interpretation or analysis. Customized from here: https://rpubs.com/cholland9/885458
County population downloaded from here https://www.census.gov/data/tables/time-series/demo/popest/2020s-counties-total.html#par_textimage
Example data is for Cali and Indiana
co-est2021-pop-06.xlsx - cali co-est2021-pop-18 (1) - Indy
library(tidyverse)
Warning: package ‘tidyverse’ was built under R version 4.0.4Registered S3 methods overwritten by 'dbplyr':
method from
print.tbl_lazy
print.tbl_sql
── Attaching packages ──────────────────────────────────────── tidyverse 1.3.1 ──
✔ ggplot2 3.3.5 ✔ purrr 0.3.4
✔ tibble 3.1.4 ✔ dplyr 1.0.10
✔ tidyr 1.2.1 ✔ stringr 1.5.0
✔ readr 2.0.1 ✔ forcats 0.5.1
Warning: package ‘ggplot2’ was built under R version 4.0.5Warning: package ‘tibble’ was built under R version 4.0.5Warning: package ‘tidyr’ was built under R version 4.0.5Warning: package ‘readr’ was built under R version 4.0.5Warning: package ‘purrr’ was built under R version 4.0.3Warning: package ‘dplyr’ was built under R version 4.0.5Warning: package ‘stringr’ was built under R version 4.0.5Warning: package ‘forcats’ was built under R version 4.0.3── Conflicts ─────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag() masks stats::lag()
covid_raw <- read_csv("https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_confirmed_US.csv")
Rows: 3342 Columns: 1097── Column specification ───────────────────────────────────────────────────────────────────
Delimiter: ","
chr (6): iso2, iso3, Admin2, Province_State, Country_Region, Combined_Key
dbl (1091): UID, code3, FIPS, Lat, Long_, 1/22/20, 1/23/20, 1/24/20, 1/25/20, 1/26/20, ...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
nrow (covid_raw)
[1] 3342
ncol(covid_raw)
[1] 1097
covid <- select(covid_raw, state= "Province_State", county= "Admin2", contains("/") )
covid